package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.EleLock;
import com.log.LatteLogger;

public class EleLockDevice {
    private String deviceType;
    private String comNo;
    private String baudRate;

    public EleLockDevice(String devType, String com, String brn) {
        this.deviceType = devType;
        this.comNo = com;
        this.baudRate = brn;
    }

    public int EleLockReset() {
        int return_data = 0;
        try {
            if ("TGEL1".equals(this.deviceType)) {
                EleLock.comNo = this.comNo;
                EleLock.baudRate = this.baudRate;

                return_data = EleLock.EleLockReset();
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("电磁锁复位异常:" + ex.getMessage());
            return_data = -1;
        }
        return return_data;
    }

    public int CheckEleLockState() {
        int return_data = 0;
        try {
            if ("TGEL1".equals(this.deviceType)) {
                EleLock.comNo = this.comNo;
                EleLock.baudRate = this.baudRate;

                return_data = EleLock.CheckEleLockState();
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("电磁锁复位异常:" + ex.getMessage());
            return_data = -1;
        }
        return return_data;
    }

    public int OpenOrCloseLeftLock(int lockFlag) {
        int return_data = 0;
        try {
            if ("TGEL1".equals(this.deviceType)) {
                EleLock.comNo = this.comNo;
                EleLock.baudRate = this.baudRate;

                return_data = EleLock.OpenOrCloseLeftLock(lockFlag);
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("打开或关闭左侧电磁锁接口异常:" + ex.getMessage());
            LatteLogger.e("开门失败或关门失败：", ex.getMessage());
            return_data = -1;
        }
        return return_data;
    }

    public int OpenOrCloseRightLock(int lockFlag) {
        int return_data = 0;
        try {
            if ("TGEL1".equals(this.deviceType)) {
                EleLock.comNo = this.comNo;
                EleLock.baudRate = this.baudRate;

                return_data = EleLock.OpenOrCloseRightLock(lockFlag);
            }
        } catch (Exception ex) {
            LogUtil.writeExceptionLog("打开或关闭右侧电磁锁接口异常:" + ex.getMessage());
            return_data = -1;
        }
        return return_data;
    }
}
